#!/usr/bin/python
# -*-coding:utf-8-*-
import numpy as np

def filter_population_v1(population, feature_names, filter_population=None):
    population_str = [[f.name if not isinstance(f, (int, str, float)) else (feature_names[f] if isinstance(f, int) else f)
                       for f in p.program] for p in population]

    func_X_filter = [(sum([not isinstance(f, (int, str, float)) for f in p.program]) >= 2) or
                     (sum([isinstance(f, int) for f in p.program]) >= 2)
                     for p in population]

    func_X_filter_2 = [p not in filter_population for p in population_str]

    selected_population = np.array(population)[np.array(func_X_filter) & np.array(func_X_filter_2)]

    selected_population = selected_population.tolist()

    return selected_population


def filter_population_v2(population, feature_names, filter_population=None):
    population_str = [[f.name if not isinstance(f, (int, str, float)) else (feature_names[f] if isinstance(f, int) else f)
                       for f in p.program] for p in population]

    func_X_filter = [sum([isinstance(f, int) for f in p.program]) >= 2
                     for p in population]

    func_X_filter_2 = [p not in filter_population for p in population_str]

    selected_population = np.array(population)[np.array(func_X_filter) & np.array(func_X_filter_2)]

    selected_population = selected_population.tolist()

    return selected_population

